#ifndef _QUADTREE_H_
#define _QUADTREE_H_

#include <map>
#include <vector>
#include "Node.h"
#include "GameData.h"
#include "AbstractEntity.h"

using namespace std;

#define MAP1_FILE L".\\Resources\\Map\\test\\map_QT.txt"
//#define MAP1_FILE L".\\Resources\\Map\\Stage1\\map_stage1.txt"
//#define MAP1_FILE L"F:\\PROJECTS\\GAME\\Source\\Map_1"
#define MAP2_FILE L".\\Resources\\Map\\test\\map_QT_2.txt"
#define MAP3_FILE L".\\Resources\\Map\\test\\map_QT_3.txt"

class CGameData;
class AbstractEntity;
struct CollistionOutput;

class QuadTree
{
public:
	QuadTree(int GameLevel);
	~QuadTree();

	CNode* RootNode;
	CGameData* GameData;
	vector<CNode*> NodesInView;
	map<int, AbstractEntity*>* curGameObjects;

	void addObjectsToNode(int nodeId, AbstractEntity* obj);
	void addObjectToQuadTree(AbstractEntity* obj);
	void buildQuadTreeFromNodes(map<int,CNode*>* nodes);
	void GetListObjectInRect(Rect*);
	void getCollistionObjects(Rect* rect, vector<CollistionOutput*>& output);
	void getCollistionObjects(Rect* rect, vector<CollistionOutput*>& output, std::map<int, AbstractEntity*> *entities);

	void getCollistionObjects(AbstractEntity* dyObject, vector<CollistionOutput*>& output);
	void getCollistionObjects(AbstractEntity* dyObject, vector<CollistionOutput*>& output, std::map<int, AbstractEntity*> *entities);
	void changeMap(int gameLevel);

private:
	void getMapData(int gameLevel);
};

struct CollistionOutput
{
	AbstractEntity* object; // Type of collistion object
	float normalx;
	float normaly;
	float entryTime;

	CollistionOutput(AbstractEntity* object, float normalx, float normaly, float entryTime)
	{
		//this->object = new GameObjectData();
		this->object = object;
		this->normalx = normalx;
		this->normaly = normaly;
		this->entryTime = entryTime;
	}
};
#endif
